package com.plian.system.controller.or;

import com.plian.Tools.Func;
import com.plian.Tools.StringPool;
import com.plian.Tools.base.BaseController;
import com.plian.Tools.pagedata.PageData;
import com.plian.system.annotation.LogOperation;
import com.plian.system.config.Resubmit;
import com.plian.system.entity.or.InCharge;
import com.plian.system.model.R;
import com.plian.system.mybatis.support.Condition;
import com.plian.system.service.or.IInChargeService;
import com.plian.system.vo.or.InChargeVO;
import com.plian.system.wrapper.or.InChargeWrapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

/**
 * @description:分管负责人
 * @author: takeoff
 * @create: 2022/1/17 下午2:40
 */
@RestController
@AllArgsConstructor
@RequestMapping("api/incharge")
@Api(value = "分管负责人表", tags = "分管负责人表接口")
public class InChargeController extends BaseController {

    private final InChargeWrapper inChargeWrapper;

    private final IInChargeService inChargeService;

    /**
     * 详情
     */
    @PostMapping("/detail")
    @ApiOperation(value = "详情", notes = "传入realProperty")
    public R<InChargeVO> detail(@RequestBody InCharge inCharge) {
        InCharge detail = inChargeService.getOne(Condition.getQueryWrapper(inCharge));
        return R.data(inChargeWrapper.entityToVO(detail));
    }

//    /** TODO DEL
//     * 分页
//     */
//    @PostMapping("/list")
//    @ApiOperation(value = "分页", notes = "传入query")
//    public ListResult<InChargeVO> list(@RequestBody Query query) {
//        List<SearchEntity> entityList = query.getSearch();
////        if (query.getAscs()==null&&query.getDescs()==null){
////            query.setDescs("create_time");
////        }
//        QueryWrapper<InCharge> queryWrapper = SearchParamEntiy.getQueryWrapper(
//                Condition.getQueryWrapper(new InCharge()), entityList
//        );
////        IPage<InCharge> pages = inChargeService.page(Condition.getPage(query),queryWrapper);
//        List<InCharge> list = inChargeService.list(queryWrapper);
//        if (CollectionUtil.isNotEmpty(list)){
//            list = list.stream().sorted(Comparator.comparing(InCharge::getUserRole)).collect(Collectors.toList());
//        }
//        ListResult<InChargeVO> listResult = new ListResult<>(CommonCode.SUCCESS);
//        listResult.setList(inChargeWrapper.entityToVO(list));
//        listResult.setTotal(list.size());
//        return listResult;
//    }


    /**
     * 新增或修改
     */
    @PostMapping("/submit")
    @Resubmit(delaySeconds = 0)
    @LogOperation("分管负责人-提交")
    @ApiOperation(value = "新增或修改", notes = "传入realProperty")
    public R submit(@Valid @RequestBody InCharge inCharge) {
        return R.status(inChargeService.saveOrUpdate(inCharge));
    }

//    /** TODO DEL
//     * 新增或修改
//     */
//    @PostMapping("/submit-list")
//    @Resubmit(delaySeconds = 0)
//    @ApiOperation(value = "批量新增或修改", notes = "传入realProperty")
//    public R submitList( @RequestBody InChargeDTO dto) {
//        return R.status(inChargeService.saveList(dto));
//    }

    /**
     * 删除
     */
    @PostMapping("/remove")
    @LogOperation("分管负责人-删除")
    @ApiOperation(value = "逻辑删除", notes = "传入ids")
    public R remove(@RequestBody PageData pd) {
        List<String> ids = (List<String>)pd.get("ids");
        return R.status(inChargeService.deleteLogic(Func.toLongList(StringUtils.join(ids, StringPool.COMMA))));
    }

}
